package com.sell.config;

import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
import com.lly835.bestpay.config.WxPayH5Config;
import com.lly835.bestpay.service.BestPayService;
import com.lly835.bestpay.service.impl.BestPayServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * Author: Xukai
 * Description: 微信支付平台
 * CreateDate: 2018/6/26 14:18
 * Modified By:
 */
@Component
public class WechatPayConfig {

    @Autowired
    private WechatProperties properties;

    @Bean
    public WxPayService wxPayService() {
        WxPayService wxPayService = new WxPayServiceImpl();
        wxPayService.setConfig(payConfig());
        return wxPayService;
    }

    @Bean
    public WxPayConfig payConfig() {
        WxPayConfig payConfig = new WxPayConfig();
        payConfig.setAppId(properties.getMpAppId());
        payConfig.setMchId(properties.getMchId());
        payConfig.setMchKey(properties.getMchKey());
        payConfig.setKeyPath(properties.getKeyPath());
        payConfig.setNotifyUrl(properties.getNotifyUrl());
        payConfig.setTradeType(properties.getTradeType());
        return payConfig;
    }

    @Bean
    public BestPayService bestPayService() {
        BestPayServiceImpl bestPayService = new BestPayServiceImpl();
        bestPayService.setWxPayH5Config(wxPayH5Config());
        return bestPayService;
    }

    @Bean
    public WxPayH5Config wxPayH5Config() {
        WxPayH5Config wxPayH5Config = new WxPayH5Config();
        wxPayH5Config.setAppId(properties.getMpAppId());
        wxPayH5Config.setAppSecret(properties.getMpAppSecret());
        wxPayH5Config.setMchId(properties.getMchId());
        wxPayH5Config.setMchKey(properties.getMchKey());
        wxPayH5Config.setKeyPath(properties.getKeyPath());
        wxPayH5Config.setNotifyUrl(properties.getNotifyUrl());
        return wxPayH5Config;
    }
}
